package com.eastseeway.radioproject.utils;

import android.annotation.SuppressLint;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import java.util.TimeZone;

public class TimeUtils {
    public final static String FORMAT_DATE = "yyyy-MM-dd";
    public final static String FORMAT_YEAR_MONTH = "yyyy-MM";
    public final static String FORMAT_TIME = "HH:mm";
    public final static String FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm";
    public final static String FORMAT_DATE_TIME_FULL = "yyyy-MM-dd HH:mm:ss";
    public final static String FORMAT_DATE_TIME_FULL1 = "yyyy-MM-dd HH:mm:ss.SSS";
    public final static String FORMAT_MONTH_DAY_TIME = "MM月dd日 HH:mm";
    @SuppressLint("SimpleDateFormat")
    private static SimpleDateFormat sdf = new SimpleDateFormat();
    public static final int YEAR = 365 * 24 * 60 * 60;// 年
    public static final int MONTH = 30 * 24 * 60 * 60;// 月
    public static final int DAY = 24 * 60 * 60;// 天
    public static final int HOUR = 60 * 60;// 小时
    public static final int MINUTE = 60;// 分钟

    /**
     * 根据时间戳获取描述性时间，如3分钟前，1天前
     *
     * @param timestamp 时间戳 单位为毫秒
     * @return 时间字符串
     */
    public static String getDescriptionTimeFromTimestamp(long timestamp) {
        long currentTime = System.currentTimeMillis();
        long timeGap = (currentTime - timestamp) / 1000;// 与现在时间相差秒数
        System.out.println("timeGap: " + timeGap);
        String timeStr;
        if (timeGap > YEAR) {
            timeStr = timeGap / YEAR + "年";
        } else if (timeGap > MONTH) {
            timeStr = timeGap / MONTH + "月";
        } else if (timeGap > DAY) {// 1天以上
            timeStr = timeGap / DAY + "天";
        } else if (timeGap > HOUR) {// 1小时-24小时
            timeStr = timeGap / HOUR + "小时";
        } else if (timeGap > MINUTE) {// 1分钟-59分钟
            timeStr = timeGap / MINUTE + "分钟";
        } else {// 1秒钟-59秒钟
            timeStr = "刚刚";
        }
        return timeStr;
    }

    public static String getDescriptionTimeFromTimestamp(String timeStr, String format) {
        if (format == null || format.trim().isEmpty()) {
            sdf.applyPattern(FORMAT_DATE_TIME_FULL);
        } else {
            sdf.applyPattern(format);
        }
        try {
            Date date = sdf.parse(timeStr);
            return getDescriptionTimeFromTimestamp(Objects.requireNonNull(date).getTime());
        } catch (Exception e) {
            e.printStackTrace();
            return timeStr;
        }
    }


    /**
     * 根据时间戳获取指定格式的时间，如2011-11-30 08:40
     *
     * @param timestamp 时间戳 单位为毫秒
     * @param format    指定格式 如果为null或空串则使用默认格式"yyyy-MM-dd HH:MM"
     */
    public static String getFormatTimeFromTimestamp(long timestamp,
                                                    String format) {
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE);
            int currentYear = Calendar.getInstance().get(Calendar.YEAR);
            int year = Integer.parseInt(sdf.format(new Date(timestamp))
                    .substring(0, 4));
            System.out.println("currentYear: " + currentYear);
            System.out.println("year: " + year);
            if (currentYear == year) {//如果为今年则不显示年份
                sdf.applyPattern(FORMAT_MONTH_DAY_TIME);
            } else {
                sdf.applyPattern(FORMAT_DATE_TIME);
            }
        } else {
            sdf.applyPattern(format);
        }
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
        Date date = new Date(timestamp);
        return sdf.format(date);
    }

    /**
     * 根据时间戳获取时间字符串，并根据指定的时间分割数partionSeconds来自动判断返回描述性时间还是指定格式的时间
     *
     * @param timestamp      时间戳 单位是毫秒
     * @param partionSeconds 时间分割线，当现在时间与指定的时间戳的秒数差大于这个分割线时则返回指定格式时间，否则返回描述性时间
     */
    public static String getMixTimeFromTimestamp(long timestamp,
                                                 long partionSeconds, String format) {
        long currentTime = System.currentTimeMillis();
        long timeGap = (currentTime - timestamp) / 1000;// 与现在时间相差秒数
        if (timeGap <= partionSeconds) {
            return getDescriptionTimeFromTimestamp(timestamp);
        } else {
            return getFormatTimeFromTimestamp(timestamp, format);
        }
    }

    /**
     * 获取当前日期的指定格式的字符串
     *
     * @param format 指定的日期时间格式，若为null或""则使用指定的格式"yyyy-MM-dd HH:MM"
     */
    public static String getCurrentTime(String format) {
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE_TIME);
        } else {
            sdf.applyPattern(format);
        }
        return sdf.format(new Date());
    }

    /**
     * 将日期字符串以指定格式转换为Date
     *
     * @param timeStr 日期字符串
     * @param format  指定的日期格式，若为null或""则使用指定的格式"yyyy-MM-dd"
     */
    public static Date getTimeFromString(String timeStr, String format) {
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE);
        } else {
            sdf.applyPattern(format);
        }
        try {
            return sdf.parse(timeStr);
        } catch (ParseException e) {
            return new Date();
        }
    }

    /**
     * 将指定格式的日期字符串转换为年月形式的
     */
    public static String getYearMonthFromString(String timeStr, String format) {
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE);
        } else {
            sdf.applyPattern(format);
        }
        @SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_YEAR_MONTH);
        try {
            return simpleDateFormat.format(Objects.requireNonNull(sdf.parse(timeStr)));
        } catch (Exception e) {
            return timeStr;
        }
    }

    /**
     * 将指定格式的日期字符串转换为年月形式的
     */
    public static String getStringFromString(String timeStr, String format, String toFormat) {
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE);
        } else {
            sdf.applyPattern(format);
        }
        try {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat(toFormat);
            return simpleDateFormat.format(Objects.requireNonNull(sdf.parse(timeStr)));
        } catch (Exception e) {
            return timeStr;
        }
    }

    public static String transTimeStr(String time) {
        return getStringFromString(time, FORMAT_DATE_TIME_FULL, FORMAT_DATE_TIME);
    }

    public static String transTimeStr1(String time) {
        return getStringFromString(time, FORMAT_DATE_TIME_FULL, FORMAT_DATE);
    }

    public static String transTimeStr2(String time) {
        return getStringFromString(time, "HH:mm:ss", FORMAT_TIME);
    }

    public static String transTimeStr(String time, String format) {
        return getStringFromString(time, FORMAT_DATE_TIME_FULL, format);
    }

    /**
     * 将日期字符串以指定格式转换为Calendar
     *
     * @param timeStr 日期字符串
     * @param format  指定的日期格式，若为null或""则使用指定的格式"yyyy-MM-dd"
     */
    public static Calendar getCalendarFromString(String timeStr, String format) {
        Calendar calendar = Calendar.getInstance();
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE);
        } else {
            sdf.applyPattern(format);
        }
        try {
            calendar.setTime(Objects.requireNonNull(sdf.parse(timeStr)));
            return calendar;
        } catch (ParseException e) {
            calendar.setTime(new Date());
            return calendar;
        }
    }

    /**
     * 将Date以指定格式转换为日期时间字符串
     *
     * @param time   日期
     * @param format 指定的日期时间格式，若为null或""则使用指定的格式"yyyy-MM-dd"
     */
    public static String getStringFromTime(Date time, String format) {
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE);
        } else {
            sdf.applyPattern(format);
        }
        return sdf.format(time);
    }

    /**
     * 将Date以指定格式转换为日期时间字符串
     *
     * @param time   日期
     * @param format 指定的日期时间格式，若为null或""则使用指定的格式"yyyy-MM-dd"
     */
    public static String getStringFromTime(Calendar time, String format) {
        if (format == null || format.trim().equals("")) {
            sdf.applyPattern(FORMAT_DATE);
        } else {
            sdf.applyPattern(format);
        }
        return sdf.format(time.getTime());
    }


    /**
     * 获取当前时间前后几天的时间
     */
    public static String beforeAfterDate(int days) {

        long nowTime = System.currentTimeMillis();
        long changeTimes = days * 24L * 60 * 60 * 1000;

        return getStrTime(String.valueOf(nowTime + changeTimes), FORMAT_DATE);

    }

    /**
     * 获取指定时间前后几天的时间
     */
    public static String beforeAfterDate(String time, int days, String format) {
        sdf.applyPattern(format);
        Date date;
        try {
            date = sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
            date = new Date();
        }
        long changeTimes = days * 24L * 60 * 60 * 1000;

//        assert date != null;
        return getStrTime(String.valueOf(date.getTime() + changeTimes), FORMAT_DATE);

    }

    /**
     * 时间戳转字符串
     */
    public static String getStrTime(String timeStamp, String format) {

        String timeString;

        if (format == null || format.trim().isEmpty()) {
            sdf.applyPattern(FORMAT_DATE);
        } else {
            sdf.applyPattern(format);
        }

        long l = Long.parseLong(timeStamp);

        timeString = sdf.format(new Date(l));//单位秒

        return timeString;

    }


    /**
     * 根据提供的年月日获取该月份的第一天
     */
    public static String getSupportBeginDayOfMonth(Date date) {
        date.getTime();
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(date);
        startDate.set(Calendar.DAY_OF_MONTH, 1);
        startDate.set(Calendar.HOUR_OF_DAY, 0);
        startDate.set(Calendar.MINUTE, 0);
        startDate.set(Calendar.SECOND, 0);
        startDate.set(Calendar.MILLISECOND, 0);
        Date firstDate = startDate.getTime();
        sdf.applyPattern(FORMAT_DATE);
        return sdf.format(firstDate);

    }

    /**
     * 根据提供的年月获取该月份的最后一天
     */
    public static String getSupportEndDayOfMonth(Date date) {
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(date);
        startDate.set(Calendar.DAY_OF_MONTH, startDate.getActualMaximum(Calendar.DAY_OF_MONTH));
        startDate.set(Calendar.HOUR_OF_DAY, 23);
        startDate.set(Calendar.MINUTE, 59);
        startDate.set(Calendar.SECOND, 59);
        startDate.set(Calendar.MILLISECOND, 999);
        Date firstDate = startDate.getTime();
        sdf.applyPattern(FORMAT_DATE);
        return sdf.format(firstDate);
    }

    /**
     * 当天的开始时间
     */
    public static long startOfTodDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date date = calendar.getTime();
        return date.getTime();
    }

    /**
     * 当天的结束时间
     */
    public static long endOfTodDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        Date date = calendar.getTime();
        return date.getTime();
    }

    public static boolean beforeCurrent(String startTime) {
        sdf.applyPattern(FORMAT_DATE_TIME_FULL);
        try {
            Date date = sdf.parse(startTime);
            return Objects.requireNonNull(date).getTime() > System.currentTimeMillis();
        } catch (ParseException e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 判断时间字符串是否在指定时间之前
     */
    public static boolean beforeTimes(String startTime, String target) {
        sdf.applyPattern(FORMAT_DATE_TIME_FULL);
        try {
            Date date = sdf.parse(startTime);
            Date targetDate = sdf.parse(target);
            return Objects.requireNonNull(date).getTime() > Objects.requireNonNull(targetDate).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static long getDistance(String startTime) {
        sdf.applyPattern(FORMAT_DATE_TIME_FULL);
        try {
            Date date = sdf.parse(startTime);
            return Objects.requireNonNull(date).getTime() - System.currentTimeMillis();
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

    /**
     * 判断当前时间是否位于两个时间段之间
     */
    public static boolean isCurrentBetween(String startTime, String endTime) {
        sdf.applyPattern(FORMAT_DATE_TIME_FULL);
        try {
            Date startDate = sdf.parse(startTime);
            Date endDate = sdf.parse(endTime);
            return Objects.requireNonNull(startDate).getTime() < System.currentTimeMillis() && Objects.requireNonNull(endDate).getTime() > System.currentTimeMillis();
        } catch (ParseException e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 计算两个时间之间相差的时长(时分秒)
     *
     * @param startTime
     * @param endTime
     * @param format
     * @return
     */
    public static String dateDiff(String startTime, String endTime, String format) {
        // 按照传入的格式生成一个simpledateformate对象
        SimpleDateFormat sd = new SimpleDateFormat(format);
        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
        long nh = 1000 * 60 * 60;// 一小时的毫秒数
        long nm = 1000 * 60;// 一分钟的毫秒数
        long ns = 1000;// 一秒钟的毫秒数
        long diff;
        try {
            // 获得两个时间的毫秒时间差异
            diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
            long hour = diff / nh;// 计算差多少小时
            long min = diff % nh / nm;// 计算差多少分钟
            long sec = diff % nh % nm / ns;// 计算差多少秒

            String hourStr = hour < 9 ? "0" + hour : hour + "";
            String minStr = min < 9 ? "0" + min : min + "";
            String secStr = sec < 9 ? "0" + sec : sec + "";

            return hourStr + ":" + minStr + ":" + secStr;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";

    }

    /**
     * 计算两个时间之间相差的时长(天时分秒)
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public static String dateDiff(long startTime,long endTime) {
        return getDiffTime(endTime - startTime);
//        String returnValue;
//        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
//        long nh = 1000 * 60 * 60;// 一小时的毫秒数
//        long nm = 1000 * 60;// 一分钟的毫秒数
//        long ns = 1000;// 一秒钟的毫秒数
//        long diff;
//        long day;
//        // 获得两个时间的毫秒时间差异
//        diff = endTime - startTime;
//        day = diff / nd;// 计算差多少天
//        long hour = diff % nd / nh;// 计算差多少小时
//        long min = diff % nd % nh / nm;// 计算差多少分钟
//        long sec = diff % nd % nh % nm / ns;// 计算差多少秒
//        // 输出结果
//        System.out.println("时间相差：" + day + "天" + hour + "小时" + min + "分钟" + sec + "秒。");
//        if (day > 0) {
//            returnValue = day + "天" + hour + "小时" + min + "分" + sec + "秒";
//        }else if (hour > 0){
//            returnValue = hour + "小时" + min + "分" + sec + "秒";
//        }else if (min > 0){
//            returnValue = min + "分" + sec + "秒";
//        }else {
//            returnValue = sec + "秒";
//        }
//        return returnValue;
    }

    /**
     *
     * @param diffTime
     * @return
     */
    public static String getDiffTime(long diffTime){
        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
        long nh = 1000 * 60 * 60;// 一小时的毫秒数
        long nm = 1000 * 60;// 一分钟的毫秒数
        long ns = 1000;// 一秒钟的毫秒数
        long day = diffTime / nd;
        long hour = diffTime % nd / nh;// 计算差多少小时
        long min = diffTime % nd % nh / nm;// 计算差多少分钟
        long sec = diffTime % nd % nh % nm / ns;// 计算差多少秒
        if (day > 0) {
            return day + "天" + hour + "时" + min + "分" ;
        }else if (hour > 0){
            return hour + "时" + min + "分";
        }else if (min > 0){
            return min + "分";
        }else {
            return sec + "秒";
        }
    }

    /**
     * 判断当前时间是否位于某个时间点之前
     */
    public static boolean isCurrentBefore(String timeStr) {
        sdf.applyPattern(FORMAT_DATE_TIME_FULL);
        try {
            Date timeDate = sdf.parse(timeStr);
            return Objects.requireNonNull(timeDate).getTime() > System.currentTimeMillis();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static String getCurDayDate() {
        Calendar calendar = Calendar.getInstance();
        int CurYear = calendar.get(Calendar.YEAR);
        int CurMonth = calendar.get(Calendar.MONTH) + 1;
        int CurDay = calendar.get(Calendar.DATE);
        return CurYear + "-" + ((CurMonth < 10) ? "0" + CurMonth : CurMonth) + "-" + ((CurDay < 10) ? "0" + CurDay : CurDay);
    }

    /**
     * 三个月后
     *
     * @return
     */
    public static String getThreeMothLaterDate() {
        Calendar calendar = Calendar.getInstance();
        int CurYear = calendar.get(Calendar.YEAR);
        int CurMonth = calendar.get(Calendar.MONTH) + 4;
        int CurDay = calendar.get(Calendar.DATE);
        return CurYear + "-" + ((CurMonth < 10) ? "0" + CurMonth : CurMonth) + "-" + ((CurDay < 10) ? "0" + CurDay : CurDay);
    }


    public static String getCurDayDateStr() {
        Calendar calendar = Calendar.getInstance();
        int CurYear = calendar.get(Calendar.YEAR);
        int CurMonth = calendar.get(Calendar.MONTH) + 1;
        int CurDay = calendar.get(Calendar.DATE);
        return CurYear + "年" + CurMonth + "月" + CurDay + "日";
    }

    public static String getCurrentSelectedDate(int year, int month, int day) {
        String date = TimeUtils.getStringFromString(year + "-" + month + "-" + day, "", TimeUtils.FORMAT_DATE);
        return date;
    }

    /**
     * 转为字符串年月  格式：2021-04
     */
    public static String getStringYearMonth(int year, int month) {
        return year + "-" + ((month < 10) ? "0" + month : month);
    }


    public static int compare_date(String DATE1, String DATE2) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() < dt2.getTime()) {
                System.out.println("dt1 在dt2前");
                return 1;
            } else if (dt1.getTime() > dt2.getTime()) {
                System.out.println("dt1在dt2后");
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }

    /**
     * 判断当前日期是星期几
     *
     * @param pTime 设置的需要判断的时间  //格式如2021-09-08
     * @return dayForWeek 判断结果
     * @Exception 发生异常
     */
    public static String getWeek(String pTime) {
        String Week = "周";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        try {
            c.setTime(format.parse(pTime));

        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 1) {
            Week += "日";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 2) {
            Week += "一";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 3) {
            Week += "二";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 4) {
            Week += "三";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 5) {
            Week += "四";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 6) {
            Week += "五";
        }
        if (c.get(Calendar.DAY_OF_WEEK) == 7) {
            Week += "六";
        }
        return Week;
    }

    // strTime要转换的String类型的时间
    // formatType时间格式
    // strTime的时间格式和formatType的时间格式必须相同
    public static long stringToLong(String strTime, String formatType) {
        Date date = null; // String类型转成date类型
        try {
            date = stringToDate(strTime, formatType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (date == null) {
            return 0;
        } else {
            long currentTime = dateToLong(date); // date类型转成long类型
            return currentTime;
        }
    }

    // strTime要转换的string类型的时间，formatType要转换的格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日
    // HH时mm分ss秒，
    // strTime的时间格式必须要与formatType的时间格式相同
    public static Date stringToDate(String strTime, String formatType) {
        SimpleDateFormat formatter = new SimpleDateFormat(formatType);
        Date date = null;
        try {
            date = formatter.parse(strTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    // date要转换的date类型的时间
    public static long dateToLong(Date date) {
        return date.getTime();
    }

    /**
     * （昨天、今天，明天，周几)
     */
    public static String getDayWeek(String time) {
        try {
            long DAY = 24 * 60 * 60 * 1000L;
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String t1 = df.format(new Date(System.currentTimeMillis()));
            long today = df.parse(t1).getTime();
            long target = df.parse(time).getTime();
            long d = today - target;
            if (d == 0L) {
                return "今天";
            } else if (d == DAY) {
                return "昨天";
            } else if (d == -DAY) {
                return "明天";
            } else {
                return getWeek(time);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 根据今天获取昨天的日期
     *
     * @return
     */
    public static String getLastDateFromCurrent(String currentDayStr) {
        long DAY = 24 * 60 * 60 * 1000L;
        sdf.applyPattern(FORMAT_DATE);
        try {
            Date date = sdf.parse(currentDayStr);
            long time = Objects.requireNonNull(date).getTime();
            long yesterday = time - DAY;
            String yesterdayStr = longToString(yesterday, FORMAT_DATE);
            return yesterdayStr;
        } catch (ParseException e) {
            e.printStackTrace();
            return currentDayStr;
        }
    }


    /**
     * 根据今天获取明天的日期
     *
     * @return
     */
    public static String getTomorrowDateFromCurrent(String currentDayStr) {
        long DAY = 24 * 60 * 60 * 1000L;
        sdf.applyPattern(FORMAT_DATE);
        try {
            Date date = sdf.parse(currentDayStr);
            long time = Objects.requireNonNull(date).getTime();
            long Tomorrow = time + DAY;
            String TomorrowStr = longToString(Tomorrow, FORMAT_DATE);
            return TomorrowStr;
        } catch (ParseException e) {
            e.printStackTrace();
            return currentDayStr;
        }
    }

    /**
     * 根据今天获取一年后的日期
     *
     * @return
     */
    public static String getOneYearDateFromCurrent(String currentDayStr) {
        long DAY = 365 * 24 * 60 * 60 * 1000L;
        sdf.applyPattern(FORMAT_DATE);
        try {
            Date date = sdf.parse(currentDayStr);
            long time = Objects.requireNonNull(date).getTime();
            long Tomorrow = time + DAY;
            String TomorrowStr = longToString(Tomorrow, FORMAT_DATE);
            return TomorrowStr;
        } catch (Exception e) {
            e.printStackTrace();
            return currentDayStr;
        }
    }


    // currentTime要转换的long类型的时间
    // formatType要转换的string类型的时间格式
    public static String longToString(long currentTime, String formatType) {
        Date date = null; // long类型转成Date类型
        try {
            date = longToDate(currentTime, formatType);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String strTime = dateToString(date, formatType); // date类型转成String
        return strTime;
    }


    /**
     * long转换为Date类型
     * // currentTime要转换的long类型的时间
     * // formatType要转换的时间格式yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒
     */
    public static Date longToDate(long currentTime, String formatType)
            throws ParseException {
        Date dateOld = new Date(currentTime); // 根据long类型的毫秒数生命一个date类型的时间
        String sDateTime = dateToString(dateOld, formatType); // 把date类型的时间转换为string
        Date date = stringToDate(sDateTime, formatType); // 把String类型转换为Date类型
        return date;
    }

    // formatType格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒
    // data Date类型的时间
    public static String dateToString(Date data, String formatType) {
        return new SimpleDateFormat(formatType).format(data);
    }

    /**
     * 判断当前时间是否在时间范围内
     *
     * @param nowTime
     * @param startTime
     * @param endTime
     * @return boolean
     */
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }

        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }


}
